﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FriendsDisplay.aspx.cs"
    Inherits="SonCa.SocialNetwork.Web.Friends.FriendsDisplay" %>

<%@ Register Src="~/ASCX/ProfileDisplay.ascx" TagName="ProfileDisplay" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>    
    <style type="text/css">
        .hidden
        {
            visibility: visible;
        }
    </style>
    <script type="text/javascript">
        function SendInvitationRequest(obj) {
            var src = obj.src.split('/');
            if (src[src.length - 1] == "icon_addFriend.png") {
                var friendID = obj.className;
                $.ajax({
                    type: "POST",
                    url: "../Services/AjaxService.svc/SendInvitationRequest",
                    data: '{"accountID" :"' + friendID + '"}',
                    contentType: "application/json",
                    dataType: "json",
                    success: function () {
                        $(obj).attr("src", "../img/requestsended.png");
                    },
                    error: function () { }
                });
            }
        };

        function PostComment(e, obj) {
            if (e.which == 13) {
                if ($(obj).val() != '') {
                    var systemObjectRecordID = obj.className;
                    var body = obj.value;
                    $.ajax({
                        type: "POST",
                        url: "../Services/AjaxService.svc/SaveComment",
                        data: '{"statusID":"' + systemObjectRecordID + '", "body":"' + body + '"}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            var parent = $(obj).parent().parent().children(".mgbot16");
                            if (parent.attr("class") == "mgbot16") {
                                parent.after(response.d);
                            }
                            else {
                                $(obj).parent().parent().prepend("<div class='mgbot16'>" + response.d + "</div>");
                            }
                            $(obj).val('');
                        },
                        error: function () { }
                    });
                }
                e.preventDefault();
            }
        }

        function Rating(obj) {
            var arr = obj.className.split(';');
            if (arr != '') {
                $.ajax({
                    type: "POST",
                    url: "../Services/AjaxService.svc/SaveRating",
                    data: JSON.stringify({ forAccountID: arr[0], statusID: arr[1] }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == true) {
                            var lblLike = $(obj).parent(".title9").children(".title10");
                            var e = $(lblLike).text();                            
                            var numberPlus = parseInt(e) + 1;
                            $(lblLike).text(numberPlus.toString());
                        }
                    },
                    error: function () { }
                });
            }
        }

        function Unlike(obj) {
            var arr = obj.className.split(';');
            if (arr != '') {
                $.ajax({
                    type: "POST",
                    url: "../Services/AjaxService.svc/SaveUnlike",
                    data: JSON.stringify({ forAccountID: arr[0], statusID: arr[1] }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == true) {
                            var lblUnLike = $(obj).parent(".title9").children(".title10");
                            var e = $(lblUnLike).text();                            
                            var numberPlus = parseInt(e) + 1;
                            $(lblUnLike).text(numberPlus.toString());
                        }
                    },
                    error: function () { }
                });
            }
        }

        function Share(obj) {
            var arr = obj.className.split(';');
            if (arr != '') {
                $.ajax({
                    type: "POST",
                    url: "../Services/AjaxService.svc/SaveShare",
                    data: JSON.stringify({ forAccountID: arr[0], statusID: arr[1] }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == true) {
                            $(obj).parent(".title9").hide();
                        }
                    },
                    error: function () { }
                });
            }
        }
    </script>
</head>
<body>
    <form id="ab" runat="server">
    <asp:Repeater ID="rptFriend" runat="server" OnItemDataBound="repFriends_ItemDataBound">
        <ItemTemplate>
            <uc1:ProfileDisplay ID="pdProfileDisplay" runat="server" ShowFriendRequestButton="true" />
        </ItemTemplate>
    </asp:Repeater>
    </form>
</body>
</html>
